//
//  TravelLineOrderEditFooter.m
//  Traveling
//
//  Created by Northwan on 15/6/11.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "TravelLineOrderEditFooter.h"
#import "SelectDateView.h"
#import "LoginCtrl.h"
#import "CustomShowView.h"
@interface TravelLineOrderEditFooter()

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *constraint;//联系人距离顶部

@property (nonatomic, weak) CustomShowView *showView;
@end
@implementation TravelLineOrderEditFooter

+(instancetype)initFooterView{
    return [[[NSBundle mainBundle]loadNibNamed:@"TravelLineOrderEditFooter" owner:nil options:nil]lastObject];
}

-(void)awakeFromNib{
    [self.startTimeBtn setTitle:[Utils stringWithDate:[NSDate date] formatterStr:@"yyyy-MM-dd"] forState:UIControlStateNormal];
}

- (IBAction)tapRemove:(id)sender {
   NSInteger count =  self.countLabel.text.integerValue;
    if(count<=1){
        count = 1;
    }else{
         count--;
    }
    [self.countLabel setText:[NSString stringWithFormat:@"%ld",count]];
}

- (IBAction)tapAdd:(id)sender {
    NSInteger count =  self.countLabel.text.integerValue;
    count++;
    [self.countLabel setText:[NSString stringWithFormat:@"%ld",count]];
}

- (IBAction)tapNext:(id)sender {
    if (ISBLANK(self.nameLabel.text)) {
        [DialogUtils showTips:@"请输入联系人姓名"];
        return;
    }
    
    if (ISBLANK(self.phoneLabel.text) || ![self.phoneLabel.text isValidatePhone]) {
        [DialogUtils showTips:@"手机号码格式有误"];
        return;
    }
    
    
    if (isLogin) {
        if (self.operation) {
            self.operation();
        }
    }else{
        //跳到登录页面
        LoginCtrl *ctrl = [[LoginCtrl alloc] init];
        [self.viewController.navigationController pushViewController:ctrl animated:YES];
    }
}

-(void)initData:(HomeItemDetailHeaderModel *)result{
    if(result.type == TravelLineDetailType){
    
    }else if (result.type ==  TravelSpecialtyDetailType){
        [self.tipsLabel setHidden:YES];
        [self.startTimeBtn setHidden:YES];
        self.constraint.constant = 20;
    }
    [self.priceLabel setText:[NSString stringWithFormat:@"￥%.1f",result.currentPrice]];
}

- (IBAction)selectTimeBtn:(UIButton *)sender {
    SelectDateView *dateView = [SelectDateView dateViewWithResult:^(NSString *dateStr, NSDate *date) {
        [self.showView hideWithanim:YES];
        self.showView = nil;
        [sender setTitle:dateStr forState:UIControlStateNormal];
    } currentDate:[NSDate date] minDate:[NSDate date]];
    
    dateView.width = SCREENW-16;
    dateView.height = 254;
    
    CustomShowView *showView = [[CustomShowView alloc] initWithCustomView:dateView];
    [showView setBackgroundColor:RGBAColor(0, 0, 0, 0.5)];
    self.showView = showView;
    [self.showView showWithanim:YES];
    
}


@end
